﻿using System.Web.Security;
using EzDesk.Core.Interface;
using EzDesk.Utility.Log;
using EzDesk.Core.Model;

namespace EzDesk.Core.ServiceImpl.Services
{
    public partial class CoreClientService : ICoreClientService
    {
        private const string defaultIconName = "default.png";

        private ICoreService _coreService;
        private IOperationProperties _operationProperties;

        public  CoreClientService(
            ICoreService coreService,
            IOperationProperties operationProperties
            )
        {
            this._operationProperties = operationProperties;
            this._coreService = coreService;

            LogEx.TRACE("CoreService - CoreClientService", "初始化CoreClientService");
            // todo: 将各个service加入服务字典
            //appServicesDic = new Dictionary<string, IAppService>();
            //appServicesDic.Add("Message", Container.Resolve<ITopicService>() as IAppService);
            //appServicesDic.Add("Attendance", Container.Resolve<IAttendanceService>() as IAppService);
            //appServicesDic.Add("Project", Container.Resolve<IProjectService>() as IAppService);
        }

        public CoreClientService()
        {
            this._operationProperties = new WebOperationProperties();
            this._coreService = new CoreService();

            LogEx.TRACE("CoreService - CoreClientService", "初始化CoreClientService");
        }

        public Organization GetOrganizationInfo()
        {
            var innerOrg = _coreService.GetOrganizationInfo();
            innerOrg.IconUrl = getUploadImageUrl(innerOrg.Icon);
            return innerOrg;
        }


        #region [ private methods ]
        private string getIconUrl(string iconName)
        {

            if (string.IsNullOrEmpty(iconName))
            {
                iconName = defaultIconName;
            }

            return "http://" + GetClientBaseUrl() + "/Content/Icons/" + iconName;
        }


        private string getTargetUrlFromFuncUrl(string funcUrl)
        {
            return "http://" + GetClientBaseUrl() + funcUrl;
        }

        private string getUploadImageUrl(string iconName)
        {
            if (string.IsNullOrEmpty(iconName))
            {
                iconName = defaultIconName;
            }
            return "http://" + GetClientBaseUrl() + "/Content/upload/" + iconName;
        }

        #endregion
    }
}
